#!/usr/bin/env python
# encoding: utf-8
"""
@summary: 计算日活跃用户数;map端输出日期和suv以及pv;在同一个map中进行聚合
@author: hongxingfan
@since: 2014年8月12日    上午9:58:23
"""
import sys
import time

# 日期和pv的实体，用于放置在list中
class Entity:
    def __init__(self, date, pv):
        self.date = date
        self.pv = pv
        
    def __str__(self):
        print("%d:%d" % (self.date, self.pv))

if __name__ == "__main__":
    
    hash_users = {}
    
    for line in sys.stdin:
        line = line.strip()
        
        cols = line.split("\t")
        domain = cols[4]
        url = cols[5]
        # 过滤掉无用的url
        if "wmh-auto-tab" in url or "pic.auto.sohu.com" == domain:
            continue
        
        date = time.localtime(float(cols[0]))  # 日期格式转化
        date = time.strftime("%Y%m%d", date)
        suv = cols[3]
        pv = 1
        entity = Entity(date, pv)
        
        # 判断suv是否已经在hash_users中
        if suv in hash_users:
            # 遍历查找list中的日期是否等于当前日期
            list = hash_users.get(suv)
            isFind = False
            for l in list:
                if l.date == date:
                    l.pv += pv
                    isFind = True
                    break
            if not isFind:
                list.append(entity)
        else:
            hash_users[suv] = [entity]
            
    # 打印hash_users，hash_users的value是list
    for (k, v) in hash_users.items():
        values = ""
        for entity in v:
            values += entity.date + ":" + str(entity.pv) + ";"
        print("%s\t%s" % (k, values))
